package com.aceitunaproject.shared.exceptions.gamerules;

import java.util.LinkedList;
import java.util.List;

import com.aceitunaproject.shared.exceptions.gamerules.EnumIllegalAction;

/**
 * @author Federico Bergstein
 *
 * Exception to return when a given action violates the game's rules
 *
 * Contains a list of the reasons why the action is invalid
 *
 */
public class IllegalActionException extends Exception {

	
	private static final long serialVersionUID = -4223744410877610008L;

	private List<EnumIllegalAction> reasons = new LinkedList<EnumIllegalAction>();

	
	public IllegalActionException(List<EnumIllegalAction> reasons)
	{
		this.reasons = reasons;
	}
	
	public IllegalActionException(EnumIllegalAction reason)
	{
		this.reasons.add(reason);
	}
	
	/**
	 * @param reasons the reasons why the action is illegal
	 */
	public void setReasons(List<EnumIllegalAction> reasons) {
		this.reasons = reasons;
	}

	/**
	 * @return the reasons why the action is illegal
	 */
	public List<EnumIllegalAction> getReasons() {
		return reasons;
	}
	
	@Override
	public String getMessage()
	{
		String reasonsString = " - ";
		
		for (EnumIllegalAction action : reasons) {
			reasonsString += action.name();
		}
		return "Illegal Action" + reasonsString;
	}
	
	
	
	
	
}
